<template>
  <z-paging ref="pagingRef" v-model="list" @query="queryList">
    <template #top>
      <MrCustom bg-color="bg-gradual-blue " is-back>
        <template #backText>
          返回
        </template>
      </MrCustom>
    </template>
    <view v-for="(item,index) in list" :key="index">
      <uni-card @click="handleRead(item)">
        <view style="display: flex;flex: 1;justify-content: space-between;">
          <view style="display: flex;">
            <uni-badge v-if="!item.isRead" size="small" :is-dot="true" text="0" absolute="rightTop"
                       :offset="[-5, -5]"></uni-badge>
            <uni-badge v-else size="small" type="primary" :is-dot="true" text="0" absolute="rightTop"
                       :offset="[-5, -5]"></uni-badge>
            <view style="margin-left: 15px;vertical-align: -5px;">{{ item.isRead ? '已读' : '未读' }}</view>
          </view>
          <view>{{ item.receiveUsername ? '私信' : '通知' }}</view>
        </view>
        <view style="font-weight: bold;font-size: 24px;margin-left: 15px">{{ item.title }}</view>
        <view style="display: flex;flex-direction: row-reverse;font-size: 12px"> 发布于
          {{ myMoment(item.updateTime).format("MMMDo HH:mm") }}
        </view>
      </uni-card>
    </view>
  </z-paging>
</template>

<script setup lang="ts">
import api from "@/api";
import {ref} from "vue";
import myMoment from "@/utils/common/myMoment";
import {useUserStore} from "@/store";
import MrCustom from "@/components/common/MrCustom.vue";

const userStore =useUserStore()
const pagingRef = ref()

const list = ref()

/**
 * 读取消息
 * @param row
 */
const handleRead = (row: any) => {
  uni.navigateTo({
    url: '/pages/user/message/notice/detail?params=' + encodeURIComponent(JSON.stringify(row)),
    success:()=>{
      row.isRead=1
    }
  })
}

const queryList = (pageNo: any, pageSize: any) => {
  api.notice.queryList({
    pageNo: pageNo,
    pageSize: pageSize,
    andParams: '{}',
    orParams: '{}',
    orderParams: '{}',
  }).then(res => {
    if (res && res.data.code === 0) {
      let tmp = res.data.data
      pagingRef.value.complete(tmp);
    }
  })
}




</script>

<style scoped>

</style>